<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>

	<div class="page-header">
		<h1><?=$studentId ? '编辑学生信息' : '新增学生'?></h1>
	</div>
	<div class="col-xs-12">
		<form class="form-horizontal" id="student-form">
			<input type="hidden" name="id" value="<?=$studentInfo['id']?>" />
			<input type="hidden" name="face_image" value="<?=$studentInfo['face_image']?>" />

			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">所属校区：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" disabled="" value="<?=$campusInfo['campus_name']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">学生名称：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="realname" placeholder="请填写学生名称" value="<?=$studentInfo['realname']?>" 
						<?php if($rmxSchool['school_from']): ?>
							readonly 
						<?php endif ?>
					/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">联系电话：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="mobile" placeholder="请填写学生联系电话" value="<?=$studentInfo['mobile']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">学号：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="username" placeholder="请填写学生学号" value="<?=$studentInfo['username']?>" 
						<?php if($rmxSchool['school_from']): ?>
							readonly 
						<?php endif ?>
					/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">性别：</label>
				<div class="col-sm-6">
					<select class="form-control" name="gender"
						<?php if($rmxSchool['school_from']): ?>
							disabled 
						<?php endif ?>
					>
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
					<?php if($rmxSchool['school_from']): ?>
						<input type="hidden" name="gender">
					<?php endif ?>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">物理卡号：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="realcard" placeholder="请填写学生物理卡号" value="<?=$studentInfo['realcard']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">职务：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="job" placeholder="请填写学生职务，如：班长，组长" value="<?=$studentInfo['job']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">座位号：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="seatno" placeholder="请填写座位号" value="<?=$studentInfo['seat_no']?>" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">行政班：</label>
				<div class="col-sm-6">
					<select class="chosen-select form-control tag-input-style" id="class-select" data-placeholder="选择学生所读行政班" name="class_id"
						<?php if($rmxSchool['school_from']): ?>
							disabled 
						<?php endif ?>
					>
						<?php foreach($classList as $class): ?>
							<option value="<?=$class['id']?>"><?=$class['class_name']?></option>
						<?php endforeach; ?>
						<?php if($rmxSchool['school_from']): ?>
							<input type="hidden" name="class_id">
						<?php endif ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">教学班：</label>
				<div class="col-sm-6">
					<select class="chosen-select form-control tag-input-style" id="teach-class-select" data-placeholder="选择学生所读教学班" name="teaching_class_id" multiple="multiple"
						<?php if($rmxSchool['school_from']): ?>
							disabled 
						<?php endif ?>
					>
						<?php foreach($teachClass as $class): ?>
							<option value="<?=$class['id']?>"><?=$class['class_name']?></option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">选修班：</label>
				<div class="col-sm-6">
					<select class="chosen-select form-control tag-input-style" id="elective-class-select" data-placeholder="选择学生所读选修班" name="elective_class_id" multiple="multiple"
						<?php if($rmxSchool['school_from']): ?>
							disabled 
						<?php endif ?>
					>
						<?php foreach($electiveClass as $class): ?>
							<option value="<?=$class['id']?>"><?=$class['class_name']?></option>
						<?php endforeach; ?>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">
					<a href="javascript:;" data-rel="tooltip" data-original-title="学生人脸图像，用于学生考勤人脸识别"><i class="fa fa-question-circle"></i></a> 人脸图像：
				</label>
				<div class="col-sm-6">
					<?php if($studentInfo['face_image']): ?>
						<a href="javascript:;" id="upload-img">
							<img class="fit-cover" src="<?=$studentInfo['face_image']?>" width="160" height="160" />
						</a>
					<?php else: ?>
						<a href="javascript:;" id="upload-img">
							<img class="fit-cover" src="<?=$staticAdminUrl?>assets/images/upload.png" width="160" height="160" />
						</a>
					<?php endif; ?>
				</div>
			</div>
			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</button>
				</div>
			</div>
			<?php if($rmxSchool['school_from']): ?>
					<select style="visibility:hidden;" class="chosen-select form-control tag-input-style" id="teach-class-select" data-placeholder="选择学生所读教学班" name="teaching_class_id" multiple="multiple">
						<?php foreach($teachClass as $class): ?>
							<option value="<?=$class['id']?>"><?=$class['class_name']?></option>
						<?php endforeach; ?>
					</select>
					<select style="visibility:hidden;" class="chosen-select form-control tag-input-style" id="elective-class-select" data-placeholder="选择学生所读选修班" name="elective_class_id" multiple="multiple">
						<?php foreach($electiveClass as $class): ?>
							<option value="<?=$class['id']?>"><?=$class['class_name']?></option>
						<?php endforeach; ?>
					</select>
			<?php endif ?>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	$(function(){
		// 上传图片对象
		$("#upload-img").uploader({
			"server":  '<?=UP_FORM_URL?>',
			"authorization": "<?=$signature?>",
			"policy": "<?=$policy?>",
			"callback": function(response) {
				var imgFile = "<?=UP_URL?>" + response.url;
				$("#upload-img").find("img").attr("src", imgFile);
				$("[name=face_image]").val(imgFile);
			}
		});

		<?php if($studentInfo): ?>
			$("[name=class_id]").val("<?=$studentInfo['class_id']?>");

			// 教学班集合
			<?php if($studentInfo['teaching_class_id']): ?>
				var teachClassArray = "<?=$studentInfo['teaching_class_id']?>".split(",");
				for(var i in teachClassArray) {
					$("[name=teaching_class_id] [value="+ teachClassArray[i] +"]").attr("selected", "selected");
				}
			<?php endif; ?>
			// 选修班集合
			<?php if($studentInfo['elective_class_id']): ?>
				var electiveClassArray = "<?=$studentInfo['elective_class_id']?>".split(",");
				for(var i in electiveClassArray) {
					$("[name=elective_class_id] [value="+ electiveClassArray[i] +"]").attr("selected", "selected");
				}
			<?php endif; ?>
			// 性别
			$("[name=gender]").val("<?=$studentInfo['gender']?>");
		<?php endif; ?>

		// 行政班下拉选择
		$('#class-select').chosen({
			search_contains: true
		}); 
		// 教学班下拉选择
		$("#teach-class-select").chosen({
			search_contains: true
		}); 
		$("#teach-class-select").trigger("liszt:updated");
		// 选修班下拉选择
		$("#elective-class-select").chosen({
			search_contains: true
		}); 
		$("#elective-class-select").trigger("liszt:updated");

		// 提交表单
		var form = $("#student-form");
		var submitUrl = "<?=admin_url('school/save_student_action')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('school/student')?>";
				}
			});
		})
	})
</script>